package util;

import java.util.Date;
import java.util.List;

public class StringParser {

	
	public static float[] getFloats(String pValue) {
		String[] values = pValue.split(" ");
		float[] fValues = new float[values.length];
		for (int i = 0; i < fValues.length; i++) {
			fValues[i] = Float.parseFloat(values[i]);
		}
		
		return fValues;
	}
	
	/**
	 * "value0 value1 value2"
	 * @param pArray
	 * @return
	 */
	public static String toString(Object[] pArray, String pSplit) {
		StringBuffer b = new StringBuffer();
		for (Object o : pArray) {
			b.append(o.toString()).append(pSplit);
		}
		
		if (pArray.length > 0) b.delete(b.length() - pSplit.length(), b.length());
		
		return b.toString();
	}
	
	/**
	 * "value0 value1 value2"
	 * @param pList
	 * @return
	 */
	public static String toString(List<?> pList, String pSplit) {
		StringBuffer b = new StringBuffer();
		for (Object o : pList) {
			b.append(o.toString()).append(pSplit);
		}
		
		if (pList.size() > 0) b.delete(b.length() - pSplit.length(), b.length());
		
		return b.toString();
	}
	
	public static String toString(Date pDate) {
		if (pDate == null) {
			return null;
		} else {
			int y = pDate.getYear() + 1900;
			int m = pDate.getMonth() + 1;
			int d = pDate.getDate();
			return String.format("%04d%02d%02d", y, m, d);
		}
	}

}
